<?php
/**
 *
 * 版权所有：河南常新宏达网络科技<www.hncxhd.com>
 * 作    者：zxl
 * 日    期：2017-2-10
 * 版    本：1.0.0
 * 功能说明：升级控制器。
 *
 **/
namespace Admin\Controller;
use Vendor\Tree;


class ProvinceController extends ComController{
       
     //省级生源
    public function province(){
    	
		// $p = isset($_GET['p']) ? intval($_GET['p']) : '1';
		// $pagesize = 20;#每页数量
        // $offset = $pagesize * ($p - 1);//计算记录偏移量
        // $count = M('xs_dc_sy_jyxx')->count();
        // $UStudents = M('xs_dc_sy_jyxx')->select();
        // print_r($UStudents);
        // exit;
        // $page = new \Think\Page($count, $pagesize);
        // $page = $page->show();
		// $this->assign('UStudents',$UStudents);
		// $this->assign('page',$page);
         $sql="SELECT COLUMN_NAME,COLUMN_COMMENT FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'cx_xs_dc_sy_jyxx' AND TABLE_SCHEMA ='jyxxgl'";
          $zs=M()->query($sql);
          $aa=[];
          $bb=array_values($zs);
          foreach ($bb as $key => $value) {
              // print_r($value['column_comment']);
               array_push($aa,$value['column_comment']);
          }
             array_unshift($aa,'');
             // echo count($aa);
           
          // $cc=['1','2'];
          // print_r($cc);
          // exit;
            $colModel=M('col_model')->select();
            // echo count($colModel);
           
            foreach ($colModel as $key => $value) {
            	 $colModel[$key][name]=strtolower($value[name]);
            }
            // print_r(json_encode($colModel));
            // exit;
            // exit;
            $ccc=$colModel;
          $this->assign('aa',json_encode($aa));
          //$this->assign('colModel',json_encode($colModel));
          $this->assign('ccc',$colModel);
          // $this->assign('colModel',json_encode($colModel));
		      $this->display();
    }
    public function getProvinceData(){
          $UStudents = M('xs_dc_sy_jyxx')->select();
          $count = M('xs_dc_sy_jyxx')->count();  

          $this->ajaxReturn($UStudents);
           
    }
     public function Padd(){
    	$user=I('post.');
      // print_r($user);
      // exit;
    	$isuser=M('xs_dc_sy_jyxx')->where("XH=$user[xh] and SFZHM=$user[sfzhm]")->find();
      
    	if($isuser){
    		echo "0";
    	}else{
        foreach ($user as $key => $value) {
        $key=strtoupper($key);
        $aaa[$key]=$value;
      }
	    	$res=M('xs_dc_sy_jyxx')->add($aaa);
        echo $res;
    	}
    	if($res){
    		echo "1";
    	}else{
    		echo "2";
    	}
    	//$this->display();
    }
    //省级生源修改修改
    public function Pedit(){
    	
    	$data=I('post.');
    	// print_r($data);
    	//echo count($data);
    	array_pop($data);
    	foreach ($data as $key => $value) {
    		$key=strtoupper($key);
    		$aaa[$key]=$value;
    	}
    	
    	//print_r($aaa);
    	$user=M('xs_dc_sy_jyxx')->where("XH=".$aaa[XH])->save($aaa);
    	echo $user;
    }

    //删除省级学生信息
    public function Pdel(){
	    	$id = I('post.id'); 	
	        if($id){	
					$map='XH in ('.$id.')';
			   }else{
			   	    echo error;
			   }
	         $delrec=M('xs_dc_sy_jyxx')->where($map)->delete();   
	         addlog('删除了'.$delrec.'个校级生源');
	         echo $delrec;    
    }


}
